<template>
	<view class="">
		<view v-for="(item,index) in list" :key="index" class="list b">
			<view class="u-flex u-row-between">
				<view style="font-weight: bold;font-size: 35rpx;">{{item.cardName}}</view>
				<view>每日限时{{item.freeTime}}分钟</view>
			</view>
			<view class="u-flex u-row-between u-margin-top-20">
				<view style="font-size: 32rpx;font-weight: bold;">￥{{item.price}}</view>
				<view class="buy" @click="buy(item)">
					购买
				</view>
			</view>
		</view>
		<u-loadmore :status="initial.status" v-if="list.length" />
	</view>
</template>

<script>
	import loader from '@/common/loadPage.js';
	export default {
		mixins: [loader],
		data() {
			return {
				list: [],
				initial: {
					geturl: "/api/index/card",
					parm: {
						store_id: ''
					},
					isPage: true
				},
			}
		},
		onLoad(option) {
			if (option.id) {
				this.initial.parm.store_id = option.id
			}
		},
		onShow() {
			this.getGoods()
		},
		methods: {
			buy(item) {
				this.$u.post('/api/indent/buyCard', {
					card_id: item.id,
					store_id: this.id,
				}).then(res => {
					if (res == null) {
						this.$refs.uToast.show({
							title: '领取成功',
							type: 'success',

						})
					} else {
						var packages = res.package;
						var {
							noncestr,
							timestamp,
							signtype,
							paysign
						} = res
						payway.wx(timestamp, noncestr, packages, signtype, paysign).then(
							res => {
								this.$refs.uToast.show({
									title: '购买成功',
									type: 'success',
								})
							}).catch(err => {})
					}
				}).catch(err => {

				})


			},
		}
	}
</script>

<style>
	.list {
		padding: 20rpx;
		color: #fff;
		border-radius: 20rpx;
		margin: 20rpx auto;
		width: 700rpx;
	}

	.b {
		background: linear-gradient(94deg, #4BA6FF 0%, #0064C6 100%);
	}

	.g {
		background: linear-gradient(90deg, #21D676 0%, #0BBC75 100%);
	}

	.buy {
		padding: 7rpx 15rpx;
		background: #fff;
		border-radius: 20rpx;
		color: #0064C6;
		font-weight: bold;
	}
</style>
